/*
** add_list.c for 42sh in /home/demesy_j/svn/quarante-deuxsh/trunk
**
** Made by julien demesy
** Login   <demesy_j@epitech.net>
**
** Started on  Mon Mar 12 11:16:56 2012 julien demesy
** Last update Tue Mar 13 11:38:31 2012 julien demesy
*/

#include	<stdlib.h>
#include	"list.h"

void		add_before(t_list *element, char *val)
{
  t_list	*new_element;

  new_element = malloc(sizeof(*new_element));
  if (new_element != NULL)
    {
      new_element->data = val;
      new_element->prev = element->prev;
      new_element->next = element;
      element->prev->next = new_element;
      element->prev = new_element;
    }
}

void		add_after(t_list *element, char *val)
{
  t_list	*new_element;

  new_element = malloc(sizeof(*new_element));
  if (new_element != NULL)
    {
      new_element->data = val;
      new_element->prev = element;
      new_element->next = element->next;
      element->next->prev = new_element;
      element->next = new_element;
    }
}

void		add_begin(t_list *root, char *val)
{
  add_after(root, val);
}

void		add_end(t_list *root, char *val)
{
  add_before(root, val);
}
